using System;
using System.Data;
using System.Data.OleDb;
using System.Collections;
using System.Configuration;
using PCSComUtils.DataAccess;
using PCSComUtils.PCSExc;
using PCSComUtils.Common;
using System.Runtime.InteropServices;
namespace PCSComMaterials.Inventory.DS
{
	public class IV_MoveToInspectionDetailDS 
	{
		public IV_MoveToInspectionDetailDS()
		{
		}
		private const string THIS = "PCSComMaterials.Inventory.DS.IV_MoveToInspectionDetailDS";

	
		///    <summary>
		///       This method uses to add data to IV_MoveToInspectionDetail
		///    </summary>
		///    <Inputs>
		///        IV_MoveToInspectionDetailVO       
		///    </Inputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <History>
		///       Thursday, June 23, 2005
		///    </History>


		public void Add(object pobjObjectVO)
		{
			const string METHOD_NAME = THIS + ".Add()";
			 
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS =null;
			try
			{
				IV_MoveToInspectionDetailVO objObject = (IV_MoveToInspectionDetailVO) pobjObjectVO;
				string strSql = String.Empty;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand("", oconPCS);
				
				strSql=	"INSERT INTO IV_MoveToInspectionDetail("
				+ IV_MoveToInspectionDetailTable.INSPECTION_FLD + ","
				+ IV_MoveToInspectionDetailTable.MRP_FLD + ","
				+ IV_MoveToInspectionDetailTable.TRANSFERQUANTITY_FLD + ","
				+ IV_MoveToInspectionDetailTable.MOVETOINSPECTIONID_FLD + ","
				+ IV_MoveToInspectionDetailTable.STOCKUMID_FLD + ","
				+ IV_MoveToInspectionDetailTable.PRODUCTID_FLD + ")"
				+ "VALUES(?,?,?,?,?,?)";

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MoveToInspectionDetailTable.INSPECTION_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MoveToInspectionDetailTable.INSPECTION_FLD].Value = objObject.Inspection;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MoveToInspectionDetailTable.MRP_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MoveToInspectionDetailTable.MRP_FLD].Value = objObject.MRP;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MoveToInspectionDetailTable.TRANSFERQUANTITY_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[IV_MoveToInspectionDetailTable.TRANSFERQUANTITY_FLD].Value = objObject.TransferQuantity;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MoveToInspectionDetailTable.MOVETOINSPECTIONID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MoveToInspectionDetailTable.MOVETOINSPECTIONID_FLD].Value = objObject.MoveToInspectionID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MoveToInspectionDetailTable.STOCKUMID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MoveToInspectionDetailTable.STOCKUMID_FLD].Value = objObject.StockUMID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MoveToInspectionDetailTable.PRODUCTID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MoveToInspectionDetailTable.PRODUCTID_FLD].Value = objObject.ProductID;


				
				ocmdPCS.CommandText = strSql;
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
	

	

		///    <summary>
		///       This method uses to add data to IV_MoveToInspectionDetail
		///    </summary>
		///    <Inputs>
		///        IV_MoveToInspectionDetailVO       
		///    </Inputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <History>
		///       Thursday, June 23, 2005
		///    </History>

		public void Delete(int pintID)
		{
			const string METHOD_NAME = THIS + ".Delete()";
			string strSql = String.Empty;
			strSql=	"DELETE " + IV_MoveToInspectionDetailTable.TABLE_NAME + " WHERE  " + "MoveToInspectionDetailID" + "=" + pintID.ToString();
			OleDbConnection oconPCS=null;
			OleDbCommand ocmdPCS =null;
			try
			{
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
				ocmdPCS = null;

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}



			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
	

	

		///    <summary>
		///       This method uses to add data to IV_MoveToInspectionDetail
		///    </summary>
		///    <Inputs>
		///        IV_MoveToInspectionDetailVO       
		///    </Inputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <History>
		///       Thursday, June 23, 2005
		///    </History>

		public object GetObjectVO(int pintID)
		{
			const string METHOD_NAME = THIS + ".GetObjectVO()";
			DataSet dstPCS = new DataSet();
			
			OleDbDataReader odrPCS = null;
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				strSql=	"SELECT "
				+ IV_MoveToInspectionDetailTable.MOVETOINSPECTIONDETAILID_FLD + ","
				+ IV_MoveToInspectionDetailTable.INSPECTION_FLD + ","
				+ IV_MoveToInspectionDetailTable.MRP_FLD + ","
				+ IV_MoveToInspectionDetailTable.TRANSFERQUANTITY_FLD + ","
				+ IV_MoveToInspectionDetailTable.MOVETOINSPECTIONID_FLD + ","
				+ IV_MoveToInspectionDetailTable.STOCKUMID_FLD + ","
				+ IV_MoveToInspectionDetailTable.PRODUCTID_FLD
				+ " FROM " + IV_MoveToInspectionDetailTable.TABLE_NAME
				+" WHERE " + IV_MoveToInspectionDetailTable.MOVETOINSPECTIONDETAILID_FLD + "=" + pintID;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				odrPCS = ocmdPCS.ExecuteReader();

				IV_MoveToInspectionDetailVO objObject = new IV_MoveToInspectionDetailVO();

				while (odrPCS.Read())
				{ 
				objObject.MoveToInspectionDetailID = int.Parse(odrPCS[IV_MoveToInspectionDetailTable.MOVETOINSPECTIONDETAILID_FLD].ToString().Trim());
				objObject.Inspection = int.Parse(odrPCS[IV_MoveToInspectionDetailTable.INSPECTION_FLD].ToString().Trim());
				objObject.MRP = int.Parse(odrPCS[IV_MoveToInspectionDetailTable.MRP_FLD].ToString().Trim());
				objObject.TransferQuantity = Decimal.Parse(odrPCS[IV_MoveToInspectionDetailTable.TRANSFERQUANTITY_FLD].ToString().Trim());
				objObject.MoveToInspectionID = int.Parse(odrPCS[IV_MoveToInspectionDetailTable.MOVETOINSPECTIONID_FLD].ToString().Trim());
				objObject.StockUMID = int.Parse(odrPCS[IV_MoveToInspectionDetailTable.STOCKUMID_FLD].ToString().Trim());
				objObject.ProductID = int.Parse(odrPCS[IV_MoveToInspectionDetailTable.PRODUCTID_FLD].ToString().Trim());

				}		
				return objObject;					
			}
			catch(OleDbException ex)
			{			
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			

			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}


		///    <summary>
		///       This method uses to add data to IV_MoveToInspectionDetail
		///    </summary>
		///    <Inputs>
		///        IV_MoveToInspectionDetailVO       
		///    </Inputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <History>
		///       Thursday, June 23, 2005
		///    </History>
		
	
		public void Update(object pobjObjecVO)
		{
			const string METHOD_NAME = THIS + ".Update()";

			IV_MoveToInspectionDetailVO objObject = (IV_MoveToInspectionDetailVO) pobjObjecVO;
			

			//prepare value for parameters
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				strSql=	"UPDATE IV_MoveToInspectionDetail SET "
				+ IV_MoveToInspectionDetailTable.INSPECTION_FLD + "=   ?" + ","
				+ IV_MoveToInspectionDetailTable.MRP_FLD + "=   ?" + ","
				+ IV_MoveToInspectionDetailTable.TRANSFERQUANTITY_FLD + "=   ?" + ","
				+ IV_MoveToInspectionDetailTable.MOVETOINSPECTIONID_FLD + "=   ?" + ","
				+ IV_MoveToInspectionDetailTable.STOCKUMID_FLD + "=   ?" + ","
				+ IV_MoveToInspectionDetailTable.PRODUCTID_FLD + "=  ?"
				+" WHERE " + IV_MoveToInspectionDetailTable.MOVETOINSPECTIONDETAILID_FLD + "= ?";

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MoveToInspectionDetailTable.INSPECTION_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MoveToInspectionDetailTable.INSPECTION_FLD].Value = objObject.Inspection;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MoveToInspectionDetailTable.MRP_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MoveToInspectionDetailTable.MRP_FLD].Value = objObject.MRP;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MoveToInspectionDetailTable.TRANSFERQUANTITY_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters[IV_MoveToInspectionDetailTable.TRANSFERQUANTITY_FLD].Value = objObject.TransferQuantity;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MoveToInspectionDetailTable.MOVETOINSPECTIONID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MoveToInspectionDetailTable.MOVETOINSPECTIONID_FLD].Value = objObject.MoveToInspectionID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MoveToInspectionDetailTable.STOCKUMID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MoveToInspectionDetailTable.STOCKUMID_FLD].Value = objObject.StockUMID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MoveToInspectionDetailTable.PRODUCTID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MoveToInspectionDetailTable.PRODUCTID_FLD].Value = objObject.ProductID;

				ocmdPCS.Parameters.Add(new OleDbParameter(IV_MoveToInspectionDetailTable.MOVETOINSPECTIONDETAILID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[IV_MoveToInspectionDetailTable.MOVETOINSPECTIONDETAILID_FLD].Value = objObject.MoveToInspectionDetailID;


				ocmdPCS.CommandText = strSql;
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}

		}


		///    <summary>
		///       This method uses to add data to IV_MoveToInspectionDetail
		///    </summary>
		///    <Inputs>
		///        IV_MoveToInspectionDetailVO       
		///    </Inputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <History>
		///       Thursday, June 23, 2005
		///    </History>

		public DataSet List()
		{
			const string METHOD_NAME = THIS + ".List()";
			DataSet dstPCS = new DataSet();
			
		

			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				
				strSql=	"SELECT "
				+ IV_MoveToInspectionDetailTable.MOVETOINSPECTIONDETAILID_FLD + ","
				+ IV_MoveToInspectionDetailTable.INSPECTION_FLD + ","
				+ IV_MoveToInspectionDetailTable.MRP_FLD + ","
				+ IV_MoveToInspectionDetailTable.TRANSFERQUANTITY_FLD + ","
				+ IV_MoveToInspectionDetailTable.MOVETOINSPECTIONID_FLD + ","
				+ IV_MoveToInspectionDetailTable.STOCKUMID_FLD + ","
				+ IV_MoveToInspectionDetailTable.PRODUCTID_FLD
					+ " FROM " + IV_MoveToInspectionDetailTable.TABLE_NAME;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();
				
				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS,IV_MoveToInspectionDetailTable.TABLE_NAME);

				return dstPCS;
			}
			catch(OleDbException ex)
			{
   				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}


		}


		///    <summary>
		///       This method uses to add data to IV_MoveToInspectionDetail
		///    </summary>
		///    <Inputs>
		///        IV_MoveToInspectionDetailVO       
		///    </Inputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <History>
		///       Thursday, June 23, 2005
		///    </History>
		
		public void UpdateDataSet(DataSet pdstData)
		{
			const string METHOD_NAME = THIS + ".UpdateDataSet()";
			string strSql;
			OleDbConnection oconPCS =null;
			OleDbCommandBuilder odcbPCS ;
			OleDbDataAdapter odadPCS = new OleDbDataAdapter();

			try
			{
				strSql=	"SELECT "
				+ IV_MoveToInspectionDetailTable.MOVETOINSPECTIONDETAILID_FLD + ","
				+ IV_MoveToInspectionDetailTable.INSPECTION_FLD + ","
				+ IV_MoveToInspectionDetailTable.MRP_FLD + ","
				+ IV_MoveToInspectionDetailTable.TRANSFERQUANTITY_FLD + ","
				+ IV_MoveToInspectionDetailTable.MOVETOINSPECTIONID_FLD + ","
				+ IV_MoveToInspectionDetailTable.STOCKUMID_FLD + ","
				+ IV_MoveToInspectionDetailTable.PRODUCTID_FLD 
		+ "  FROM " + IV_MoveToInspectionDetailTable.TABLE_NAME;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				odadPCS.SelectCommand = new OleDbCommand(strSql, oconPCS);
				odcbPCS = new OleDbCommandBuilder(odadPCS);
				pdstData.EnforceConstraints = false;
				odadPCS.Update(pdstData,IV_MoveToInspectionDetailTable.TABLE_NAME);

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{

					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);				
				}
				
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}

		}
	}
}
